# -*- coding: UTF-8 -*-
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
import math

class Fight:
    ATCTIME = 60
    def __init__(self,cam,game_obj,player):
        self.cam = cam
        self.player = player
        self.game_obj = game_obj
        pass
    
    def initFight(self):
        self.isMoving = False
    
    def setKey(self, key, value):
        self.game_obj.keyMap[key] = value
    
    def runFight(self,attacker,atK_object):
        if (self.game_obj.keyMap["atk1"]!=0):
            #print self.player.ralph.getPos()

            if attacker.isAttack == False:
                #判断是否符合射程标准
                x1 = atK_object.ralph.getX() - attacker.ralph.getX()
                y1 = atK_object.ralph.getY() - attacker.ralph.getY()
                d = math.sqrt(   x1**2+  y1**2   )          
                attacker.player_data.getRealValue()
                if d<=  attacker.player_data.real_atk_range:
                    
                    #开始播放打击动作
                    attacker.atkTimer=Fight.ATCTIME
                    self.player.start_atk1 = self.player.rightHand.getP() 
                    self.player.start_atk2 = self.player.ralph.getH() 
                    attacker.isAttack = True
                else :
                    print 'too far away!'
                #数值计算开始
                
                
        if attacker.isAttack == True:
            attacker.atkTimer = attacker.atkTimer-1
            if attacker.atkTimer == 0:
                attacker.isAttack = False
                self.player.rightHand.setP(self.player.start_atk1) 
                self.player.ralph.setH(self.player.start_atk2)
             
            attacker.attack()
            
 


        